package com.difsonapps.android.joinme;

import com.difsonapps.android.joinme.db.Contact;
import com.difsonapps.android.joinme.db.DatabaseHandler;

import android.app.Fragment;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class TchatFragment extends Fragment{

	long id;
	DatabaseHandler db;
	View rootView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if(rootView!=null)
			return rootView;
	     rootView = inflater.inflate(R.layout.fragment_tchat,
				container, false);
		
		Intent intent = this.getActivity().getIntent();
		String idContact = intent.getStringExtra("id");
		id = Long.valueOf(idContact);
		db = new DatabaseHandler(this.getActivity().getApplicationContext());
		Uri dataUri = ContactsContract.Data.CONTENT_URI;
		Cursor dataCursor = this.getActivity().getContentResolver().query(dataUri, null, 
				ContactsContract.Data.CONTACT_ID + "=" + id, 
				null, null);
		Contact contact = db.getContactContactId(id);
		if(contact==null)
		{
			
			return rootView;
		}
		getActivity().getActionBar().setTitle(contact.getName());
		return rootView;
	}
}
